package Leetcode.ArrayAndLinkedList.swapPairs24;

/**
 * 给定 1->2->3->4, 你应该返回 2->1->4->3.
 */
public class Solution {

    public ListNode swapPairs(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode next = head.next;
        head.next = swapPairs(next.next);
        next.next = head;

        return next;
    }

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4,5,6};
        ListNode node = new ListNode(nums);
        System.out.println(node);
        Solution solution = new Solution();
        System.out.println(solution.swapPairs(node));
    }
}
